package org.v2ray.rocket.proxy.support.network

import android.content.Context
import android.os.Build
import okhttp3.OkHttpClient
import rxhttp.RxHttpPlugins
import java.util.concurrent.TimeUnit

/**
 * RxHttp配置类
 * 提供OkHttpClient和RxHttpPlugins的初始化
 */
object RxHttpConfig {
    
    /**
     * 提供OkHttpClient
     */
    private fun provideOkHttpClient(): OkHttpClient {
        return OkHttpClient.Builder()
            .connectTimeout(5, TimeUnit.SECONDS)
            .readTimeout(5, TimeUnit.SECONDS)
            .writeTimeout(5, TimeUnit.SECONDS)
            .build()
    }
    
    /**
     * 提供RxHttpPlugins
     */
    fun provideRxHttpPlugins(context: Context): RxHttpPlugins {
        return RxHttpPlugins.init(provideOkHttpClient())
            .setDebug(true) // 开发环境设置为true，生产环境设置为false
            .setOnParamAssembly { param ->
                // 添加全局参数
                param.add("User-Agent", "AndroidOS${Build.VERSION.RELEASE}")
                param.add("pl", "android")
                param.add("version", "7.0.6")
                param.add("ap", "com.ssrlive.hunmiao")
                param.add("ch", "main")
            }
    }
} 